<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标段编号">
              <j-input placeholder="请输入标段编号" v-model="queryParam.bidSectionCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标段名称">
              <j-input placeholder="请输入标段名称" v-model="queryParam.bidSectionName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleReview(record)">评标</a> -->
          <a @click="handleReview(record)" v-if="record.status==1 || record.status == 2">评标</a>
          <a disabled="true" v-else>评标</a>
          <a-divider type="vertical" />
          <a @click="showRecommendModal(record)">专家推荐记录</a>
          <a-divider type="vertical" />
          <a @click="handleResult(record)" v-if="record.status==2 || record.status == 3">评标详情</a>
          <a disabled="true" v-else>评标详情</a>
          <a-divider type="vertical" />
          <a @click="handleReport(record)" v-if="record.status==1 || record.status == 3" >评标报告</a>
           <a disabled="true" v-else>评标报告</a>
          <!-- <a-divider type="vertical" />
          <a @click="handleProjectDetail(record)">详情</a> -->
        </span>
      </a-table>
    </div>
    <review-modal ref="modalForm" @ok="modalFormOk"></review-modal>
    <SignModal ref="signModalRef" @closeAndShowModal="closeAndShowModal" @ok="loadData"/>
    <ex-evaluation-report-modal ref="reportModalRef"></ex-evaluation-report-modal>
    <result-info-modal ref="modalResult"></result-info-modal>
    <ExpertRecommendRecordModal ref="recommendRecordRef"/>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import { httpAction, getAction } from '@/api/manage'
import ReviewModal from './ReviewModal'
import SignModal from './review/SignInfoModal.vue'
import ExEvaluationReportModal from './report/ExEvaluationReportModal.vue'
import ResultInfoModal from './ResultInfo'
import ExpertRecommendRecordModal from '@views/exPingbiao/review/ExpertRecommendRecordModal.vue'

import { Modal } from 'ant-design-vue'
import { mapGetters } from 'vuex'
export default {
  name: 'ExProjectList',
  mixins: [JeecgListMixin],
  components: {
    ReviewModal,
    ResultInfoModal,
    SignModal,
    ExEvaluationReportModal,
    ExpertRecommendRecordModal
  },
  data() {
    return {
      description: '项目标段管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '标段编号',
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: '标段编号',
          align: 'center',
          dataIndex: 'bidSectionCode',
        },
        {
          title: '标段名称',
          align: 'left',
          dataIndex: 'bidSectionName',
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projectCode',
        },
        {
          title: '项目名称',
          align: 'left',
          dataIndex: 'projectName',
        },
         {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
           customRender: function (text) {
            if(text==1){
              return '组长选取中'
            }
            if(text==2){
              return '评标中'
            }
             if(text==3){
              return '评标结束'
            }
          },
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          sorter: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exProject/exSection/list',
        sign: '/exPingbiao/exPingbiaoExpert/sign',
        querySignInfo: '/exPingbiao/exPingbiaoExpert/querySignInfo',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam:{
      },
      disableMixinCreated:true
    }
  },
  created() {
    this.queryParam.expertId =this.userInfo.id;
    this.getSuperFieldList()
    this.loadData();
    //初始化字典配置 在自己页面定义
    this.initDictConfig();
  },
  computed: {
    ...mapGetters(['userInfo']),
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    searchReset() {
      this.queryParam = {
        expertId: this.userInfo.id
      }
      this.loadData(1);
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'projectId', text: '项目标识码 (guid)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectCode', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'regionCode', text: '项目所在行政区域代码', dictCode: 'sys_kf_area' })
      fieldList.push({ type: 'string', value: 'investProjectCode', text: '投资项目统一代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'address', text: '项目地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'legalPerson', text: '项目法人', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'industriesType',
        text: '项目行业分类',
        dictCode: 'sys_industry_category',
      })
      fieldList.push({ type: 'string', value: 'fundSource', text: '资金来源', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contributionScale', text: '出资比例', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectScale', text: '项目规模', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactor', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactInformation', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'islixiang', text: '是否立项', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'notlixiang', text: '不立项原因', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptName', text: '监督部门名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'superviseDeptCode', text: '监督部门代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalName', text: '项目审批文件名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalNumber', text: '项目审批文号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'approvalAuthority', text: '项目审批单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'attachmentCode', text: '附件关联标识号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'platformCode', text: '交易系统标识码', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'stateOwnedFund', text: '国有资金（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'stateOwnedFundRatio', text: '国有资金比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'privateFund', text: '私有资金（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'privateFundRatio', text: '私有资金比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignFund', text: '外国政府及组织投资（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignFundRatio', text: '外国政府及组织投资比例', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignPrivateFund', text: '境外私人投资（万元）', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'foreignPrivateFundRatio', text: '境外私人投资比例', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '项目状态', dictCode: 'sys_common_status' })
      fieldList.push({ type: 'int', value: 'version', text: '版本号', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleSubmit(row) {
      var that = this
      httpAction(this.url.submitAudit + '?id=' + row.id, row, 'post')
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData()
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    handleReview(record) {
      if(record.status == '1'){
        this.$refs.signModalRef.showModal(record);
      }else{
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = record.projectName + ' 【 ' + record.bidSectionName + ' 】'
        this.$refs.modalForm.disableSubmit = true
      }
      // 1
      // this.$refs.signModalRef.showModal(record);
      // 2
      // this.querySignInfo(record);
      // 3
    },
    handleResult(record){
      //评标详情
        this.$refs.modalResult.show(record)
        this.$refs.modalResult.title = record.projectName + ' 【 ' + record.bidSectionName + ' 】'
    },
    // 展示推荐记录
    showRecommendModal(record){
      this.$refs.recommendRecordRef.showModal(record)
    },
    closeAndShowModal(record){
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = record.projectName + ' 【 ' + record.bidSectionName + ' 】'
      this.$refs.modalForm.disableSubmit = true
    },
    handleReport(record){
      this.$refs.reportModalRef.add(record.id)
      this.$refs.reportModalRef.title = record.projectName + ' 【 ' + record.bidSectionName + ' 】'
    },
    querySignInfo (record) {
      var that = this
      getAction(this.url.querySignInfo, { sectionId: record.id })
        .then((res) => {
          this.signFlag = res.result;
          if(!res.result){
            Modal.confirm({
              title: '提示',
              content: '您还没有签到，无法评标？',
              okText: '立即签到',
              cancelText: '取消',
              onOk: async () => {
                try {
                  this.sign(record);
                } catch (error) {
                }
              },
            })
          }else{
            this.$refs.signModalRef.showModal(record);
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    sign (record) {
      var that = this
      getAction(this.url.sign, { sectionId: record.id })
        .then((res) => {
          this.$message.success('签到成功')
          this.querySignInfo(record);
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    handleProjectDetail(row) {
      var that = this
      //this.$router.push({ path: '/exProject/info', query: { projectId: row.id,projectName:row.projectName } })
      let url = `/#/exProject/projectInfo?projectId=${row.id}&projectName=${row.projectName}`
      window.open(url, '_blank')
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
